﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;

public partial class masterdata_Product_Uoms_Detali : PageBase
{
    Product_UomsManager manager = new Product_UomsManager();

    private int code = 0;
    private const string UomsCode = "code";
    private string _ProductID ="";

    protected void Page_Load(object sender, EventArgs e)
    {
 //       _Uoms = Request.QueryString["UomsCode"];

        if (Request.QueryString[UomsCode] != null)
        {
            int.TryParse(Request.QueryString[UomsCode],out code);
        }
        _ProductID=Request.QueryString["ProductID"];

        if (!IsPostBack)
        {
            //GetUomsType();

            PRODUCT_UOMS product_uoms = manager.Load(code);
            if (product_uoms != null)
            {
                ddlUoms.SelectedValue = product_uoms.UomsCode;
                txtNum.Value = product_uoms.DENOMINATOR.ToString();
                chkYesNo.Checked = product_uoms.ACTIVE;
                txtWeight.Value = product_uoms.WEIGHT.ToString();
                txtVol.Value = product_uoms.VOLUME.ToString();
            }
        }
    }

    #region 绑定基本规格
    //public void GetUomsType()
    //{
    //    ddlUoms.DataSource = UomsManager.GetUoms(MyStateManager.DomainID);
    //    ddlUoms.DataTextField = "UomsDescription";
    //    ddlUoms.DataValueField = "UomsCode";
    //    ddlUoms.DataBind();
    //    ddlUoms.Items.Insert(0, new ListItem("-选择规格-", ""));
    //}
    #endregion

    protected void btnSave_Click(object sender, EventArgs e)
    {
        PRODUCT_UOMS product_uoms = null;

        product_uoms = manager.Load(code);

        if (product_uoms == null)
            product_uoms = new PRODUCT_UOMS();

        product_uoms.UomsCode = ddlUoms.SelectedValue;
        product_uoms.DENOMINATOR = Decimal.Parse(txtNum.Value);
        product_uoms.ACTIVE = chkYesNo.Checked;
        product_uoms.VOLUME = Decimal.Parse(txtVol.Value);
        product_uoms.WEIGHT = Decimal.Parse(txtWeight.Value);
        product_uoms.DOMAINID = MyStateManager.DomainID;
        product_uoms.PRODUCTID = Decimal.Parse(_ProductID);
        product_uoms.LAST_UPDATER = MyStateManager.Name;
        product_uoms.SELLFLAG = chkYesNo.Checked ? "1" : "0";
        product_uoms.LAST_UPDATE_TIME = long.Parse(Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTimeString(DateTime.Now));


        manager.Save(product_uoms);

        Response.Redirect(string.Format("Product_Uoms_List.aspx"));
    }
}
